package org.jeecg.modules.ParameterModule.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.ParameterModule.entity.*;
import org.jeecg.modules.ParameterModule.service.CategoryInfoService;
import org.jeecg.modules.ParameterModule.service.FormalCategoryInfoService;
import org.jeecg.modules.ParameterModule.service.TestPlateInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * 后台版号配置
 * */
@Api(tags="后台测试版号配置")
@RestController
@RequestMapping("/admin/testplate")
@Slf4j
public class TestPlateInfoController {
    @Autowired
    private CategoryInfoService test_parameterService;//测试区
    @Autowired
    private TestPlateInfoService parameterService;//测试版号区
    @Autowired
    private FormalCategoryInfoService zsparameterService;//正式区
    @Autowired
    private ISysBaseAPI sysBaseAPI;//日志API

    /**
     * 总后台查询+测试类别列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_categoryinfoList")
    public Result<?> query_test_categoryinfoList(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                 String queryName,String queryCode,String pingleiName) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCategoryPageList(page,queryName,queryCode,pingleiName);
        if(pageList.getRecords().size()>0){
            for (int i=0;i<pageList.getRecords().size();i++){
                List<QiyongListInfo> qiyongListInfo = parameterService.query_UpdatecategoryRecord(pageList.getRecords().get(i).getId().toString(),"1","0");
                if(qiyongListInfo.size()>0){
                    pageList.getRecords().get(i).setQiyongTime(qiyongListInfo.get(0).getCreateTime());
                }else {
                    pageList.getRecords().get(i).setQiyongTime(pageList.getRecords().get(i).getCreateTime());
                }
            }
        }
        return Result.ok(pageList);
    }

    /**
     * 查询所有品类列表
     * @return
     */
    @GetMapping(value = "/query_all_pinglei")
    public Result<?> query_all_pinglei(){
        List<MlccCategoryInfo> datalist = parameterService.query_allpinglei_list();
        if(datalist.size()>0){
            return Result.ok(datalist);
        }else{
            return Result.error("未找到对应数据");
        }
    }
    /**
     * 修改测试版号
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_category_plate")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_category_plate(@RequestBody MlccCategoryTestInfo testInfo) {
        System.out.println(testInfo.getCategoryName() + "===" + testInfo.getImg());
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String create_by = sysUser.getUsername();
        try {
            if(testInfo.getCategoryName()==null || "".equals(testInfo.getCategoryName())){
                return Result.error("版号名称不能为空");
            }
            if(testInfo.getCategoryCode()==null || "".equals(testInfo.getCategoryCode())){
                return Result.error("版号编号不能为空");
            }
            if(testInfo.getNumbers()==null || "".equals(testInfo.getNumbers())){
                return Result.error("序号不能为空");
            }
            if(testInfo.getImg()==null || "".equals(testInfo.getImg())){
                return Result.error("图片不能为空");
            }
            testInfo.setUpdateBy(create_by);
            //根据id查询详情
            MlccCategoryTestInfo datainfo = test_parameterService.select_testcategoryDetail(testInfo.getId().toString());
            if(datainfo!=null){
                if(!testInfo.getCategoryCode().equals(datainfo.getCategoryCode())){//改了编号
                    MlccCategoryTestInfo banhao_detail = parameterService.queryCategoryDetailBytype(testInfo.getCategoryCode(),10);//根据品类编号查询品类
                    if(banhao_detail!=null){
                        return Result.error("该系统已存在该编号，请更换一个新的编号");
                    }else {
                        int code = parameterService.update_category_plate(testInfo);
                        if(code>0){
                            return Result.ok("编辑成功");
                        }else {
                            return Result.error("编辑失败");
                        }
                    }
                }else {
                    int code = parameterService.update_category_plate(testInfo);
                    if(code>0){
                        return Result.ok("编辑成功");
                    }else {
                        return Result.error("编辑失败");
                    }
                }

            }else {
                return Result.error("该版号异常");
            }

        }catch (Exception e){
            return Result.error("该系统已存在该编号，请更换一个新的编号");
        }
    }

    /**
     * 根据品类id统计数据
     * @return
     */
    @GetMapping(value = "/count_data_banhaoId")
    public Result<?> count_data_banhaoId(@RequestParam(name="category_id")String category_id){
        CountDataInfo countDataInfo = new CountDataInfo();
        int xiuzinum1 = parameterService.count_xiuzi_color(category_id);
        int xiuzinum2 = parameterService.count_xiuzi_font(category_id);
        int xiuzinum3 = parameterService.count_xiuzi_img(category_id);
        int xiuzinum4 = parameterService.count_xiuzi(category_id);
        countDataInfo.setDingzhiNum(parameterService.count_dingzhi(category_id));
        countDataInfo.setHuchiNum(parameterService.count_huchi(category_id));
        countDataInfo.setXiuziNum(xiuzinum1+xiuzinum2+xiuzinum3+xiuzinum4);
        countDataInfo.setZhuangseNum(parameterService.count_zhuangse(category_id));
        countDataInfo.setJingtiNum(parameterService.count_jing_bodysize(category_id));
        countDataInfo.setChengNum(parameterService.count_cheng_bodysize(category_id));
        countDataInfo.setFanxiuNum(parameterService.count_fanxiu(category_id));
        countDataInfo.setGongyiNum(parameterService.count_gongyi(category_id));
        countDataInfo.setFuliao(parameterService.count_fuliao(category_id));
        countDataInfo.setStandardcode(parameterService.count_standardcode(category_id));
        return Result.ok(countDataInfo);
    }

    /**
     * 修改正式或者测试的类别的状态
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_category_status")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_category(@RequestBody Map<String,Object> params) {
        String parameter_id = params.get("parameter_id").toString();
        String type = params.get("type").toString();
        String status = params.get("status").toString();
        //type:1正式，2测试  status:0正常，1假删除
        System.out.println("===" + parameter_id);
        if(parameter_id==null || "".equals(parameter_id)){
            return Result.error("参数id不能为空");
        }
        try {
            int code = parameterService.update_category_status(type,status,parameter_id);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }

    /**
     * 根据版号id查询所有定制项
     * @return
     */
    @GetMapping(value = "/query_dingzhiByplateId")
    public Result<?> query_dingzhiBypingleiId(@RequestParam(name="category_id")String category_id){
        List<SmalltemplateTestInfo> datalist = parameterService.query_alldingzhiByplateId(category_id);
        if(datalist.size()>0){
            return Result.ok(datalist);
        }else{
            return Result.error("未找到对应数据");
        }
    }
    /**
     * 修改定制项状态
     * @param
     * @return boolean
     */
    @PutMapping(value = "/change_dingzhi_status")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> change_dingzhi_status(@RequestBody Map<String,Object> params) {
        String dingzhi_id = params.get("dingzhi_id").toString();
        String type = params.get("type").toString();
        String status = params.get("status").toString();
        System.out.println("===" + dingzhi_id);
        if(dingzhi_id==null || "".equals(dingzhi_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.change_dingzhi_status(type,status,dingzhi_id);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }
    /**
     * 修改定制项下面的参数状态
     * @param
     * @return boolean
     */
    @PutMapping(value = "/change_dingzhi_canshu_status")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> change_dingzhi_canshu_status(@RequestBody Map<String,Object> params) {
        String dingzhi_id = params.get("dingzhi_id").toString();
        String type = params.get("type").toString();
        String status = params.get("status").toString();
        System.out.println("===" + dingzhi_id);
        if(dingzhi_id==null || "".equals(dingzhi_id)){
            return Result.error("定制id不能为空");
        }
        try {
            int code = parameterService.change_dingzhi_canshu_status(type,status,dingzhi_id);
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }
    /**
     * 总后台查询+测试定制项下的参数列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_dignzhipartmer")
    public Result<?> query_test_dignzhipartmer(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                               @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                               String topcategory_id,String module_id,String queryName) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCanshuPageList(page,topcategory_id,module_id,queryName);
        return Result.ok(pageList);
    }

    /**
     * 根据类别id查询版号详情
     * @return
     */
    @GetMapping(value = "/query_PlateDetailById")
    public Result<?> query_PlateDetailById(String category_id) {
        MlccCategoryTestInfo pageList = parameterService.query_plateDetailById(category_id);
        if(pageList!=null){
            return Result.ok(pageList);
        }else {
            return Result.error("暂无数据");
        }
    }
    /**
     * 根据类型和类别id查询启用记录
     * @return
     */
    @GetMapping(value = "/query_qiyongRecord_categotyId")
    public Result<?> query_qiyongRecord_categotyId(String type,String category_id) {
        QiyongListInfo pageList = parameterService.query_qiyongRecord_categotyId(type,category_id);
        QiyongListInfo qiyongListInfo = new QiyongListInfo();
        if("1".equals(type)){
            if(pageList==null){//版号还没启用-就拿版号的创建时间
                //根据版号id查询版号详情-测试版
                MlccCategoryTestInfo categorydetail = parameterService.query_plateDetailById(category_id);
                if(categorydetail!=null){
                    qiyongListInfo.setCreateTime(categorydetail.getCreateTime());
                }
            }else {
                qiyongListInfo = pageList;
            }
        }else {
            qiyongListInfo = pageList;
        }
        return Result.ok(qiyongListInfo);
    }


    /**
     * 总后台查询+版号下的辅料-里布
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_libu")
    public Result<?> categoryinfo_material_libu(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = parameterService.query_material_libuPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+版号下的辅料-低领里
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_dilingli")
    public Result<?> categoryinfo_material_dilingli(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                    @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                    String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = parameterService.query_material_dilingliPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+版号下的辅料-纽扣
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/categoryinfo_material_buttons")
    public Result<?> categoryinfo_material_buttons(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                   @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                   String queryName, String queryCode,String category_id) {
        Page<CategoryMaterialInfo> page = new Page<CategoryMaterialInfo>(pageNo, pageSize);
        IPage<CategoryMaterialInfo> pageList = parameterService.query_material_buttonsPageList(page,category_id,queryName,queryCode);
        return Result.ok(pageList);
    }
    /**
     * 配置版号下的辅料
     * @param
     * @return boolean
     */
    @PostMapping(value = "/set_plate_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> set_plate_material(@RequestBody CategoryMaterialInfo testInfo) {
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_plate_libu(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }
    /**
     * 删除计量局
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_plate_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_plate_material(@RequestBody Map<String,Object> params) {
        String material_id = params.get("material_id").toString();
        System.out.println("===" + material_id);
        if(material_id==null || "".equals(material_id)){
            return Result.error("辅料id不能为空");
        }
        try {
            int code = parameterService.delete_plate_libu(material_id);
            if(code>0){
                return Result.ok("移除成功");
            }else {
                return Result.error("移除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }


    /**
     * 定制项下的参数--版号下的---全部禁用/可用
     * @param
     * @return boolean
     */
    @PutMapping(value = "/keyong_all_canshu")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> keyong_all_canshu(@RequestBody Map<String,Object> params) {
        String category_id = params.get("category_id").toString();//版号id
        String dingzhi_id = params.get("dingzhi_id").toString();
        String type = params.get("type").toString();//1正式，2测试
        String status = params.get("status").toString();
        System.out.println("==版号和定制项==" + dingzhi_id+"==="+category_id);
        try {
            int code=0;
            //执行查询所有参数根据版号id，定制项id
            List<MlccCategoryTestInfo> canshulist = parameterService.query_AllcanshuByplate_dingzhiId(category_id,dingzhi_id);
            if(canshulist.size()>0){
                for (int i=0;i<canshulist.size();i++){
                    code = parameterService.change_dingzhi_canshu_status(type,status,canshulist.get(i).getId().toString());
                }
            }
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }


    /**
     * 总后台查询+测试部位列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_locationlist")
    public Result<?> test_xiuzi_locationlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                             @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                             String category_id,String queryName,String queryTime) {
        Page<CategoryLocationTestInfo> page = new Page<CategoryLocationTestInfo>(pageNo, pageSize);
        IPage<CategoryLocationTestInfo> pageList = parameterService.query_testlocaltionPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试颜色列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_colorlist")
    public Result<?> test_xiuzi_colorlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                          @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                          String category_id,String queryName,String queryTime) {
        Page<EmbroideredColorTestInfo> page = new Page<EmbroideredColorTestInfo>(pageNo, pageSize);
        IPage<EmbroideredColorTestInfo> pageList = parameterService.query_testColorPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试部位列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_imglist")
    public Result<?> test_xiuzi_imglist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                        @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                        String category_id,String queryName,String queryTime) {
        Page<EmbroideredFontTestInfo> page = new Page<EmbroideredFontTestInfo>(pageNo, pageSize);
        IPage<EmbroideredFontTestInfo> pageList = parameterService.query_testImgPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+测试字体列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_xiuzi_fontlist")
    public Result<?> test_xiuzi_fontlist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime) {
        Page<EmbroideredFontTestInfo> page = new Page<EmbroideredFontTestInfo>(pageNo, pageSize);
        IPage<EmbroideredFontTestInfo> pageList = parameterService.query_testFontPageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }


    /**
     * 总后台查询+测试标准码/正式标准码
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/query_standardCode_pagelist")
    public Result<?> query_standardCode_pagelist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String queryName,String queryTime,String type) {
        //type 1正式，2测试
        Page<StandardCodeInfo> page = new Page<StandardCodeInfo>(pageNo, pageSize);
        IPage<StandardCodeInfo> pageList = parameterService.query_standardCode_pagelist(page,category_id,queryName,queryTime,type);
        return Result.ok(pageList);
    }
    /**
     * 根据id查询标准码详情
     * @return
     */
    @GetMapping(value = "/query_StandardCodeDetail")
    public Result<?> query_StandardCodeDetail(@RequestParam(name="id")String id){
        StandardCodeInfo datainfo = parameterService.query_standardCodeDetail(id,2);
        if(datainfo!=null){
            return Result.ok(datainfo);
        }else{
            return Result.error("未找到对应数据");
        }
    }

//    /**
//     * 查询所有标准码-上级
//     * @return
//     */
//    @GetMapping(value = "/query_allStandardCodeList")
//    public Result<?> query_allStandardCodeList(@RequestParam(name="category_id")String category_id){
//        List<AddSystemPriceInfo> datalist= parameterService.query_alladdsysprice(category_id);
//        if(datalist.size()>0){
//            return Result.ok(datalist);
//        }else{
//            return Result.error("未找到对应数据");
//        }
//    }

    /**
     * 添加标准码
     * @param
     * @return boolean
     */
    @PostMapping(value = "/add_standardcode")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> add_standardcode(@RequestBody StandardCodeInfo testInfo) {
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            //根据编号查询标砖嘛
            StandardCodeInfo isstandinfo = parameterService.query_standardCodeDetailBycode(testInfo.getCode());
            if(isstandinfo!=null){
                return Result.error("该编号已存在，请更换");
            }
            String codefanxiu = UUID.randomUUID().toString().substring(0,12);
            //8位随机数
            int random=new Random().nextInt(1000000)+1;//为变量赋随机值1-99999999;
            String category_code = codefanxiu+random;
            //赋值品类编号
            testInfo.setId(category_code);
            //赋值创建人信息
            testInfo.setCreateBy(create_by);
            testInfo.setSysOrgCode(sys_org_code);
            int code = parameterService.add_StandardCode(testInfo);
            if(code>0){
                return Result.ok("添加成功");
            }else {
                return Result.error("添加失败");
            }
        }catch (Exception e){
            return Result.error("添加失败，参数错误");
        }
    }

    /**
     * 修改标准吗
     * @param
     * @return boolean
     */
    @PutMapping(value = "/update_standardcode")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> update_standardcode(@RequestBody StandardCodeInfo testInfo) {
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String create_by = sysUser.getUsername();
        try {
            int code = 0;
            testInfo.setUpdateBy(create_by);
            //根据id查询详情
            StandardCodeInfo standardCodeInfo = parameterService.query_standardCodeDetail(testInfo.getId(),2);
            if(testInfo.getCode().equals(standardCodeInfo.getCode())){
                 code = parameterService.update_StandardCode(testInfo);
            }else {
                //根据编号查询标砖嘛
                StandardCodeInfo isstandinfo = parameterService.query_standardCodeDetailBycode(testInfo.getCode());
                if(isstandinfo!=null){
                    return Result.error("该编号已存在，请更换");
                }else {
                    code = parameterService.update_StandardCode(testInfo);
                }
            }
            if(code>0){
                return Result.ok("编辑成功");
            }else {
                return Result.error("编辑失败");
            }
        }catch (Exception e){
            return Result.error("编辑失败，参数错误");
        }
    }

    /**
     * 删除标砖吗
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_standardCode")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_standardCode(@RequestBody Map<String,Object> params) {
        String id = params.get("id").toString();
        try {
            int code = parameterService.delete_StandardCode(id);
            if(code>0){
                return Result.ok("删除成功");
            }else {
                return Result.error("删除失败");
            }
        }catch (Exception e){
            return Result.error("删除失败，参数错误");
        }
    }

    /**
     * 禁用启用---所有
     * @param
     * @return boolean
     */
    @PutMapping(value = "/change_parameter_status")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> forbidden_plate_zhuangse(@RequestBody Map<String,Object> params) {
        String id = params.get("id").toString();
        String status = params.get("status").toString();
        //1撞色，2尺寸，3返修，4工艺类型
        String type = params.get("type").toString();
        try {
            int code = parameterService.change_parameter_status(id,status,Integer.parseInt(type));
            if(code>0){
                return Result.ok("操作成功");
            }else {
                return Result.error("操作失败");
            }
        }catch (Exception e){
            return Result.error("操作失败，参数错误");
        }
    }

    /**
     * 总后台查询+撞色列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_zhuangselist")
    public Result<?> test_zhuangselist(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                       @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                       String category_id,String queryName,String queryTime) {
        Page<ContrastcolorTestInfo> page = new Page<ContrastcolorTestInfo>(pageNo, pageSize);
        IPage<ContrastcolorTestInfo> pageList = parameterService.query_testzhuangsePageList(page,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+身体尺寸
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_jinti_bodysize")
    public Result<?> test_jinti_bodysize(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                         @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                         String category_id,String type,String queryName,String queryTime) {
        Page<BodySizeTestInfo> page = new Page<BodySizeTestInfo>(pageNo, pageSize);
        IPage<BodySizeTestInfo> pageList = parameterService.query_testBodySizePageList(page,type,category_id,queryName,queryTime);
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+返修尺寸
     * @param pageNo
     * @param pageSize
     * @returntest_categoryinfoListBytype
     */
    @GetMapping(value = "/test_fanxiu_bodysize")
    public Result<?> test_fanxiu_bodysize(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                          @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                          String category_id,String queryName,String queryTime) {
        Page<CategoryFanxiuTestInfo> page = new Page<CategoryFanxiuTestInfo>(pageNo, pageSize);
        IPage<CategoryFanxiuTestInfo> pageList = parameterService.query_testFanxiuSizePageList(page,category_id,queryName,queryTime);
        if(pageList.getRecords().size()>0){
            for (int i=0;i<pageList.getRecords().size();i++){
                pageList.getRecords().get(i).setFanwei(pageList.getRecords().get(i).getMin()+"至"+pageList.getRecords().get(i).getMax());
            }
        }
        return Result.ok(pageList);
    }
    /**
     * 总后台查询+根据类型查询测试类别列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping(value = "/test_categoryinfoListBytype")
    public Result<?> test_categoryinfoListBytype(@RequestParam(name="pageNo", defaultValue="1") final Integer pageNo,
                                                 @RequestParam(name="pageSize", defaultValue="10") final Integer pageSize,
                                                 String category_id,String type,String queryName,String queryTime) {
        Page<MlccCategoryTestInfo> page = new Page<MlccCategoryTestInfo>(pageNo, pageSize);
        IPage<MlccCategoryTestInfo> pageList = parameterService.query_testCategoryPageListBytype(page,category_id,type,queryName,queryTime);
        return Result.ok(pageList);
    }


    /**
     * 同步数据
     * @param
     * @return boolean
     */
    @PostMapping(value = "/post_synchronous_data")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> post_synchronous_data(@RequestBody Map<String,Object> params) {
        String top_id = params.get("category_id").toString();//获取版号id
        String category_id = params.get("top_id").toString();//品类id
        System.out.println("传进来的版号需要的id===" + category_id + "====" + top_id);
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        String zspingleiId = top_id;//版号id
        int code2 = 0, code3 = 0, code4 = 0, code5 = 0, code6 = 0, code7 = 0, code8 = 0, code9 = 0, code10 = 0, code66 = 0;
//        try {
            if (category_id == null || "".equals(category_id)) {
                return Result.error("品类id不能为空");
            }
            /**查询正式的参数*/
            //根据品类id查询定制项
            List<SmalltemplateTestInfo> dingzhilist = parameterService.query_dingzhiBycategoryId(category_id);
            //根据品类id查询定制项下的参数
            List<MlccCategoryTestInfo> canshulist = parameterService.query_AllcanshuBypingleiId(category_id);
            //根据品类id查询互斥项
            List<MutexTestInfo> huchilist = parameterService.query_AllhuchiBypingleiId(category_id);
            //根据品类id查询绣字部位
            List<CategoryLocationTestInfo> xuzilist1 = parameterService.query_Allxiuzi1BypingleiId(category_id);
            //根据品类id查询绣字颜色
            List<EmbroideredColorTestInfo> xuzilist2 = parameterService.query_AllxiuziColorBypingleiId(category_id);
            //根据品类id查询绣字图片
            List<EmbroideredFontTestInfo> xuzilist3 = parameterService.query_AllxiuziFontBypingleiId(category_id);
            //根据品类id查询撞色
            List<ContrastcolorTestInfo> zhuangselist = parameterService.query_AllzhuangseBypingleiId(category_id);
            //根据品类id查询净体尺寸
            List<BodySizeTestInfo> bodysizelist1 = parameterService.query_AlljingtiBodysizeBypingleiId(category_id);
            //根据品类id查询返修
            List<CategoryFanxiuTestInfo> fanxiulist = parameterService.query_AllFanxiuBypingleiId(category_id);
            //根据品类id查询工艺类型
            List<MlccCategoryTestInfo> gongyilist = parameterService.query_AllGongyiBypingleiId(category_id);

            /**根据测试版号id查询测试数据*/
            //根据品类id查询定制项
            List<SmalltemplateTestInfo> test_dingzhilist = test_parameterService.query_dingzhiBycategoryId(top_id);
            //根据品类id查询定制项下的参数
            List<MlccCategoryTestInfo> test_canshulist = test_parameterService.query_AllcanshuBypingleiId(top_id);
            //根据品类id查询互斥项
            List<MutexTestInfo> test_huchilist = test_parameterService.query_AllhuchiBypingleiId(top_id);
            //根据品类id查询绣字部位
            List<CategoryLocationTestInfo> test_xuzilist1 = test_parameterService.query_Allxiuzi1BypingleiId(top_id);
            //根据品类id查询绣字颜色
            List<EmbroideredColorTestInfo> test_xuzilist2 = test_parameterService.query_AllxiuziColorBypingleiId(top_id);
            //根据品类id查询绣字图片
            List<EmbroideredFontTestInfo> test_xuzilist3 = test_parameterService.query_AllxiuziFontBypingleiId(top_id);
            //根据品类id查询撞色
            List<ContrastcolorTestInfo> test_zhuangselist = test_parameterService.query_AllzhuangseBypingleiId(top_id);
            //根据品类id查询净体尺寸
            List<BodySizeTestInfo> test_bodysizelist1 = test_parameterService.query_AlljingtiBodysizeBypingleiId(top_id);
            //根据品类id查询返修
            List<CategoryFanxiuTestInfo> test_fanxiulist = test_parameterService.query_AllFanxiuBypingleiId(top_id);
            //根据品类id查询工艺类型
            List<MlccCategoryTestInfo> test_gongyilist = test_parameterService.query_AllGongyiBypingleiId(top_id);

            /**循环删除正式的所有参数*/
            if (test_canshulist.size() > 0) {
                int code = parameterService.delete_real_dingzhi_canshu(top_id);
                System.out.println("删除正式参数==" + code);
            }
            if (test_dingzhilist.size() > 0) {
                //循环删除
                int code = parameterService.delete_real_dingzhi(top_id);
                System.out.println("删除定制项==" + code);
            }
            if (test_huchilist.size() > 0) {
                //循环删除
                int code = parameterService.delete_real_huchi(top_id);
                System.out.println("删除互斥项==" + code);
            }
            if (test_xuzilist1.size() > 0) {
                int code = parameterService.delete_real_xiuzi_location(top_id);
                System.out.println("删除绣字部位==" + code);
            }
            if (test_xuzilist2.size() > 0) {
                int code = parameterService.delete_real_xiuzi_color(top_id);
                System.out.println("删除绣字颜色==" + code);
            }
            if (test_xuzilist3.size() > 0) {
                int code = parameterService.delete_real_xiuzi_fontImg(top_id);
                System.out.println("删除绣字字体图片==" + code);
            }
            if (test_zhuangselist.size() > 0) {
                int code = parameterService.delete_real_zhuahngse(top_id);
                System.out.println("删除撞色==" + code);
            }
            if (test_bodysizelist1.size() > 0) {
                int code = parameterService.delete_real_size(top_id);
                System.out.println("删除尺寸==" + code);
            }
            if (test_fanxiulist.size() > 0) {
                int code = parameterService.delete_real_fanxiusize(top_id);
                System.out.println("删除返修==" + code);
            }
            if (test_gongyilist.size() > 0) {
                int code = parameterService.delete_real_gongyi(top_id);
                System.out.println("删除工艺类型==" + code);
            }
//            if (test_zhuangselist.size() > 0) {
//                int code = parameterService.delete_real_zhuahngse(top_id);
//                System.out.println("删除撞色==" + code);
//            }
            if (dingzhilist.size() > 0) {
                for (int i = 0; i < dingzhilist.size(); i++) {
//                    for (int k=0;i<test_dingzhilist.size();k++){
//                        if(dingzhilist.get(i).getCode().equals(test_dingzhilist.get(k).getCode())){
//                            //执行修改
//
//                        }else {
                            //循环添加定制项
                            SmalltemplateTestInfo datainfo = new SmalltemplateTestInfo();
                            datainfo.setModuleId(dingzhilist.get(i).getModuleId());
                            datainfo.setCategoryId(zspingleiId);
                            datainfo.setCode(dingzhilist.get(i).getCode());
                            datainfo.setParameter(dingzhilist.get(i).getParameter());
                            datainfo.setImgs(dingzhilist.get(i).getImgs());
                            datainfo.setNumbers(dingzhilist.get(i).getNumbers());
                            datainfo.setIstype(dingzhilist.get(i).getIstype());
                            datainfo.setRemark(dingzhilist.get(i).getRemark());
                            datainfo.setSysOrgCode(sys_org_code);
                            datainfo.setCreateBy(create_by);
                            datainfo.setStatus(0);
                            code2 = parameterService.add_dingzhi(datainfo);

//                        }
//                    }
                }
            }
            if (canshulist.size() > 0) {
                for (int i = 0; i < canshulist.size(); i++) {
                    //循环添加定制项下的参数
                    String praent_id = "";
                    SmalltemplateTestInfo ceshidingdatainfo = zsparameterService.query_dingzhiBydingzhId(canshulist.get(i).getParentId());
                    if (ceshidingdatainfo != null) {
                        //查询新增的定制项--测试版号
                        List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_testdingzhiByBanhaoId(zspingleiId);
                        if (zsdingzhi_datalist.size() > 0) {
                            for (int k = 0; k < zsdingzhi_datalist.size(); k++) {
                                if (ceshidingdatainfo.getCode().equals(zsdingzhi_datalist.get(k).getCode())) {
                                    praent_id = zsdingzhi_datalist.get(k).getId().toString();
                                }
                            }
                        }
                    }
                    MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                    datainfo.setCategoryName(canshulist.get(i).getCategoryName());
                    datainfo.setCategoryCode(canshulist.get(i).getCategoryCode());
                    datainfo.setParentId(praent_id);
                    datainfo.setImg(canshulist.get(i).getImg());
                    datainfo.setTopid(zspingleiId);
                    datainfo.setNumbers(canshulist.get(i).getNumbers());
                    datainfo.setIsType(canshulist.get(i).getIsType());
                    datainfo.setCost(canshulist.get(i).getCost());
                    datainfo.setTeamPrice2(canshulist.get(i).getTeamPrice2());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setStatus(0);
                    code3 = parameterService.add_dingzhi_canshu(datainfo);
                }
            }
            if (huchilist.size() > 0) {
                for (int i = 0; i < huchilist.size(); i++) {
                    //查询新增的定制项
                    String dingzhi1="",dingzhi2="";
                    String firstId = "",secoundId="";
                    List<SmalltemplateTestInfo> zsdingzhi_datalist = test_parameterService.query_dingzhiBycategoryId(zspingleiId);
                    SmalltemplateTestInfo ceshidingdatainfo1 = zsparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi1());
                    SmalltemplateTestInfo ceshidingdatainfo2 = zsparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi2());
                    if(ceshidingdatainfo1!=null){
                        if(zsdingzhi_datalist.size()>0){
                            for (int k=0;k<zsdingzhi_datalist.size();k++){
                                if(ceshidingdatainfo1.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                    dingzhi1 = zsdingzhi_datalist.get(k).getId().toString();
                                    break;
                                }
                            }
                        }
                    }
                    if(ceshidingdatainfo2!=null){
                        if(zsdingzhi_datalist.size()>0){
                            for (int k=0;k<zsdingzhi_datalist.size();k++){
                                if(ceshidingdatainfo2.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                    dingzhi2 = zsdingzhi_datalist.get(k).getId().toString();
                                    break;
                                }
                            }
                        }
                    }
                    //根据类别id查询类别详情
                    MlccCategoryTestInfo leibiedatainfo1 = zsparameterService.select_testcategoryDetail(huchilist.get(i).getCategoryId());
                    if(leibiedatainfo1!=null){
                        MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo1.getCategoryCode(),zspingleiId,dingzhi1);
                        if(zsleibie!=null){
                            firstId = zsleibie.getId().toString();
                        }
                    }
                    String canshuids[] = huchilist.get(i).getCategoryOther().split(",");
                    String strbody="";
                    for (String s:canshuids){
                        //根据类别id查询类别详情
                        MlccCategoryTestInfo leibiedatainfo2 = zsparameterService.select_testcategoryDetail(s);
                        if(leibiedatainfo2!=null){
                            MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo2.getCategoryCode(),zspingleiId,dingzhi2);
                            if(zsleibie!=null){
                                strbody += zsleibie.getId().toString()+",";
                            }
                        }
                    }
                    secoundId = strbody.substring(0,strbody.length()-1);
                    //循环添加互斥
                    MutexTestInfo datainfo = new MutexTestInfo();
                    datainfo.setMutexName(huchilist.get(i).getMutexName());
                    datainfo.setTopId(zspingleiId);
                    datainfo.setCategoryId(firstId);
                    datainfo.setCategoryOther(secoundId);
                    datainfo.setMutexReason(huchilist.get(i).getMutexReason());
                    datainfo.setStatus(huchilist.get(i).getStatus());
                    datainfo.setCode(huchilist.get(i).getCode());
                    datainfo.setDingzhi1(dingzhi1);
                    datainfo.setDingzhi2(dingzhi2);
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    code4 = parameterService.add_huchi(datainfo);
                }
            }
            if (xuzilist1.size() > 0) {
                for (int i = 0; i < xuzilist1.size(); i++) {
                    //循环添加绣字部位
                    CategoryLocationTestInfo datainfo = new CategoryLocationTestInfo();
                    datainfo.setCode(xuzilist1.get(i).getCode());
                    datainfo.setXiuziLocaltion(xuzilist1.get(i).getXiuziLocaltion());
                    datainfo.setCategoryId(zspingleiId);
                    datainfo.setRemark(xuzilist1.get(i).getRemark());
                    datainfo.setNumbers(xuzilist1.get(i).getNumbers());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setStatus(0);
                    code5 = parameterService.add_xiuzi_location(datainfo);
                }
            }
            if (xuzilist2.size() > 0) {
                for (int i = 0; i < xuzilist2.size(); i++) {
                    //循环添加绣字颜色
                    EmbroideredColorTestInfo datainfo = new EmbroideredColorTestInfo();
                    datainfo.setCode(xuzilist2.get(i).getCode());
                    datainfo.setColorName(xuzilist2.get(i).getColorName());
                    datainfo.setCategoryId(zspingleiId);
                    datainfo.setColorImg(xuzilist2.get(i).getColorImg());
                    datainfo.setNumbers(xuzilist2.get(i).getNumbers());
                    datainfo.setRemark(xuzilist2.get(i).getRemark());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setStatus(0);
                    code6 = parameterService.add_xiuzi_color(datainfo);
                }
            }
            if (xuzilist3.size() > 0) {
                for (int i = 0; i < xuzilist3.size(); i++) {
                    //循环添加绣字字体
                    EmbroideredFontTestInfo datainfo = new EmbroideredFontTestInfo();
                    datainfo.setCode(xuzilist3.get(i).getCode());
                    datainfo.setEmbroideredName(xuzilist3.get(i).getEmbroideredName());
                    datainfo.setCategoryId(zspingleiId);
                    datainfo.setEmbroideredImage(xuzilist3.get(i).getEmbroideredImage());
                    datainfo.setNumbers(xuzilist3.get(i).getNumbers());
                    datainfo.setRemark(xuzilist3.get(i).getRemark());
                    datainfo.setIsZitiImg(xuzilist3.get(i).getIsZitiImg());
                    datainfo.setXiuziSize(xuzilist3.get(i).getXiuziSize());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setStatus(0);
                    code66 = parameterService.add_xiuzi_fontImg(datainfo);
                }
            }
            if (zhuangselist.size() > 0) {
                for (int i = 0; i < zhuangselist.size(); i++) {
                    //循环添加撞色
                    ContrastcolorTestInfo datainfo = new ContrastcolorTestInfo();
                    datainfo.setTopId(zspingleiId);
                    datainfo.setCode(zhuangselist.get(i).getCode());
                    datainfo.setContrastColorName(zhuangselist.get(i).getContrastColorName());
                    datainfo.setCategoryId(zhuangselist.get(i).getCategoryId());
                    datainfo.setContrastColorImg(zhuangselist.get(i).getContrastColorImg());
                    datainfo.setSinglePrice2(zhuangselist.get(i).getSinglePrice2());
                    datainfo.setTeamPrice2(zhuangselist.get(i).getTeamPrice2());
                    datainfo.setDingzhiId(zhuangselist.get(i).getDingzhiId());
                    datainfo.setRemark(zhuangselist.get(i).getRemark());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    code7 = parameterService.add_zhuangse(datainfo);
                }
            }
            if (bodysizelist1.size() > 0) {
                for (int i = 0; i < bodysizelist1.size(); i++) {
                    //循环添加身体尺寸
                    BodySizeTestInfo datainfo = new BodySizeTestInfo();
                    datainfo.setBodySizename(bodysizelist1.get(i).getBodySizename());
                    datainfo.setUnit(bodysizelist1.get(i).getUnit());
                    datainfo.setModuleId(bodysizelist1.get(i).getModuleId());
                    datainfo.setCategoryId(zspingleiId);
                    datainfo.setNumbers(bodysizelist1.get(i).getNumbers());
                    datainfo.setIsJin(bodysizelist1.get(i).getIsJin());
                    datainfo.setMax(bodysizelist1.get(i).getMax());
                    datainfo.setMin(bodysizelist1.get(i).getMin());
                    datainfo.setIsBitian(bodysizelist1.get(i).getIsBitian());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    code8 = parameterService.add_testbodySize(datainfo);
                }
            }
            if (fanxiulist.size() > 0) {
                for (int i = 0; i < fanxiulist.size(); i++) {
                    //循环添加返修
                    CategoryFanxiuTestInfo datainfo = new CategoryFanxiuTestInfo();
                    datainfo.setBodySizename(fanxiulist.get(i).getBodySizename());
                    datainfo.setUnit(fanxiulist.get(i).getUnit());
                    datainfo.setCategoryId(zspingleiId);
                    datainfo.setNumbers(fanxiulist.get(i).getNumbers());
                    datainfo.setMax(fanxiulist.get(i).getMax());
                    datainfo.setMin(fanxiulist.get(i).getMin());
                    datainfo.setRemark(fanxiulist.get(i).getRemark());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setCode(fanxiulist.get(i).getCode());
                    code9 = parameterService.add_testFanxiuSize(datainfo);
                }
            }
            if (gongyilist.size() > 0) {
                for (int i = 0; i < gongyilist.size(); i++) {
                    //循环添加工艺
                    MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                    datainfo.setCategoryCode(gongyilist.get(i).getCategoryCode());
                    datainfo.setCategoryName(gongyilist.get(i).getCategoryName());
                    datainfo.setParentId(gongyilist.get(i).getParentId());
                    datainfo.setImg(gongyilist.get(i).getImg());
                    datainfo.setRemark(gongyilist.get(i).getRemark());
                    datainfo.setTopid(zspingleiId);
                    datainfo.setIsType(4);
                    datainfo.setCategorySex(gongyilist.get(i).getCategorySex());
                    datainfo.setNumbers(gongyilist.get(i).getNumbers());
                    datainfo.setSysOrgCode(sys_org_code);
                    datainfo.setCreateBy(create_by);
                    datainfo.setStatus(0);
                    code10 = parameterService.add_category_plate(datainfo);
                }
            }
        System.out.println("各个code==" + code2 + "=" + code3 + "=" + code4 + "=" + code5 + "=" + code6 + "=" + code66 + "=" + code7 + "=" + code8 + "=" + code9 + "=" + code10);
        if (code2 > 0 || code3 > 0 || code4 > 0 || code5 > 0 || code6 > 0 || code66 > 0 || code7 > 0 || code8 > 0 || code9 > 0 || code10 > 0) {
            //测试区
            zsparameterService.add_qiyong_record(zspingleiId,"1","0","数据同步成功",create_by,sys_org_code);
            return Result.ok("同步数据成功");
        } else {
            return Result.error("同步数据失败");
        }
//        }catch (Exception e){
//            return Result.error("失败，参数错误");
//        }
    }

    /**
     * 把该品类下面的属性转移到该版号上
     * @param
     * @return boolean
     */
    @PostMapping(value = "/pinglei_transfer_banhao")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> post_pinglei_transfer_banhao(@RequestBody Map<String,Object> params) {
        String category_id = params.get("category_id").toString();//获取品类id
        String banhao_name = params.get("banhao_name").toString();
        String banhao_code = params.get("banhao_code").toString();
        String banhao_remark = params.get("banhao_remark").toString();
        String banhao_numbers = params.get("banhao_numbers").toString();
        String banhao_img = params.get("banhao_img").toString();
        System.out.println("传进来的版号需要的id===" + category_id);
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
        try {
            if(category_id==null || "".equals(category_id)){
                return Result.error("品类id不能为空");
            }
            MlccCategoryTestInfo banhao_detail = parameterService.queryCategoryDetailBytype(banhao_code,10);//根据品类编号查询品类
            if(banhao_detail != null){
                return Result.error("该编号在系统已存在，请重新填写");
            }else {
                //根据品类id查询品类详情
                MlccCategoryInfo zhengshipinglei = parameterService.queryCategoryDetailById(category_id);
                //测试版号
//                Long startTs = System.currentTimeMillis(); // 当前时间戳
//                int random=new Random().nextInt(100)+1;//为变量赋随机值1-99999999;
//                String bianhao_code = "PLATE"+startTs.toString()+random;
                MlccCategoryTestInfo banhaotest = new MlccCategoryTestInfo();
                banhaotest.setCategoryName(banhao_name);
                banhaotest.setCategoryCode(banhao_code);
                banhaotest.setRemark(banhao_remark);
                banhaotest.setNumbers(Double.parseDouble(banhao_numbers));
                banhaotest.setImg(banhao_img);
                banhaotest.setTopid(category_id);//版号的上级id是品类id
                banhaotest.setIsType(3);
                banhaotest.setParentId("3");
                banhaotest.setStatus(0);//0表示启用，1表示禁用
                banhaotest.setCategorySex(zhengshipinglei.getCategorySex());
                banhaotest.setCreateBy(create_by);
                banhaotest.setSysOrgCode(sys_org_code);
                int code1 = parameterService.add_category_plate(banhaotest);//添加版号
                System.out.println("添加版号成功没===="+code1);
                int code2 = 0,code3=0,code4=0,code5=0,code6=0,code7=0,code8=0,code9=0,code10=0,code66=0;
                if(code1>0){
                    //根据品类id查询定制项
                    List<SmalltemplateTestInfo> dingzhilist = parameterService.query_dingzhiBycategoryId(category_id);
                    //根据品类id查询定制项下的参数
                    List<MlccCategoryTestInfo> canshulist = parameterService.query_AllcanshuBypingleiId(category_id);
                    //根据品类id查询互斥项
                    List<MutexTestInfo> huchilist = parameterService.query_AllhuchiBypingleiId(category_id);
                    //根据品类id查询绣字部位
                    List<CategoryLocationTestInfo> xuzilist1 = parameterService.query_Allxiuzi1BypingleiId(category_id);
                    //根据品类id查询绣字颜色
                    List<EmbroideredColorTestInfo> xuzilist2 = parameterService.query_AllxiuziColorBypingleiId(category_id);
                    //根据品类id查询绣字图片
                    List<EmbroideredFontTestInfo> xuzilist3 = parameterService.query_AllxiuziFontBypingleiId(category_id);
                    //根据品类id查询撞色
                    List<ContrastcolorTestInfo> zhuangselist = parameterService.query_AllzhuangseBypingleiId(category_id);
                    //根据品类id查询净体尺寸
                    List<BodySizeTestInfo> bodysizelist1 = parameterService.query_AlljingtiBodysizeBypingleiId(category_id);
                    //根据品类id查询返修
                    List<CategoryFanxiuTestInfo> fanxiulist = parameterService.query_AllFanxiuBypingleiId(category_id);
                    //根据品类id查询工艺类型
                    List<MlccCategoryTestInfo> gongyilist = parameterService.query_AllGongyiBypingleiId(category_id);

                    MlccCategoryTestInfo banhao_detail2 = parameterService.queryCategoryDetailBytype(banhao_code,3);//根据编号查询版号
                    if(banhao_detail2 != null){
//                        System.out.println("进来版号了没===="+banhao_detail2.getId()+"==="+banhao_detail2.getCategoryCode());
                        String zspingleiId = banhao_detail2.getId().toString();//版号id
                        if(dingzhilist.size()>0){
                            for (int i=0;i<dingzhilist.size();i++){
                                //循环添加定制项
                                SmalltemplateTestInfo datainfo = new SmalltemplateTestInfo();
                                datainfo.setModuleId(dingzhilist.get(i).getModuleId());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setCode(dingzhilist.get(i).getCode());
                                datainfo.setParameter(dingzhilist.get(i).getParameter());
                                datainfo.setImgs(dingzhilist.get(i).getImgs());
                                datainfo.setNumbers(dingzhilist.get(i).getNumbers());
                                datainfo.setIstype(dingzhilist.get(i).getIstype());
                                datainfo.setRemark(dingzhilist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setStatus(0);
                                code2 = parameterService.add_dingzhi(datainfo);
                            }
                        }
                        if(canshulist.size()>0){
                            for (int i=0;i<canshulist.size();i++){
                                //循环添加定制项下的参数
                                String praent_id = "";
                                //查询到正式的定制项
                                SmalltemplateTestInfo ceshidingdatainfo = zsparameterService.query_dingzhiBydingzhId(canshulist.get(i).getParentId());
                                if(ceshidingdatainfo!=null){
                                    //查询新增的定制项--测试版号
                                    List<SmalltemplateTestInfo> zsdingzhi_datalist = parameterService.query_testdingzhiByBanhaoId(zspingleiId);
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                praent_id = zsdingzhi_datalist.get(k).getId().toString();
                                                System.out.println("时候付哦添加了空间====="+praent_id);
                                            }
                                        }
                                    }
                                }
                                MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                                datainfo.setCategoryName(canshulist.get(i).getCategoryName());
                                datainfo.setCategoryCode(canshulist.get(i).getCategoryCode());
                                datainfo.setParentId(praent_id);
                                datainfo.setImg(canshulist.get(i).getImg());
                                datainfo.setTopid(zspingleiId);
                                datainfo.setNumbers(canshulist.get(i).getNumbers());
                                datainfo.setIsType(canshulist.get(i).getIsType());
                                datainfo.setCost(canshulist.get(i).getCost());
                                datainfo.setTeamPrice2(canshulist.get(i).getTeamPrice2());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setStatus(0);
                                code3 = parameterService.add_dingzhi_canshu(datainfo);
                            }
                        }
                        if(huchilist.size()>0){
                            for (int i=0;i<huchilist.size();i++){
                                //查询新增的定制项
                                String dingzhi1="",dingzhi2="";
                                String firstId = "",secoundId="";
                                List<SmalltemplateTestInfo> zsdingzhi_datalist = test_parameterService.query_dingzhiBycategoryId(zspingleiId);
                                SmalltemplateTestInfo ceshidingdatainfo1 = zsparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi1());
                                SmalltemplateTestInfo ceshidingdatainfo2 = zsparameterService.query_dingzhiBydingzhId(huchilist.get(i).getDingzhi2());
                                if(ceshidingdatainfo1!=null){
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo1.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                dingzhi1 = zsdingzhi_datalist.get(k).getId().toString();
                                                break;
                                            }
                                        }
                                    }
                                }
                                if(ceshidingdatainfo2!=null){
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo2.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                dingzhi2 = zsdingzhi_datalist.get(k).getId().toString();
                                                break;
                                            }
                                        }
                                    }
                                }
                                //根据类别id查询类别详情
                                MlccCategoryTestInfo leibiedatainfo1 = zsparameterService.select_testcategoryDetail(huchilist.get(i).getCategoryId());
                                if(leibiedatainfo1!=null){
                                    MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo1.getCategoryCode(),zspingleiId,dingzhi1);
                                    if(zsleibie!=null){
                                        firstId = zsleibie.getId().toString();
                                    }
                                }
                                String canshuids[] = huchilist.get(i).getCategoryOther().split(",");
                                String strbody="";
                                for (String s:canshuids){
                                    //根据类别id查询类别详情
                                    MlccCategoryTestInfo leibiedatainfo2 = zsparameterService.select_testcategoryDetail(s);
                                    if(leibiedatainfo2!=null){
                                        MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo2.getCategoryCode(),zspingleiId,dingzhi2);
                                        if(zsleibie!=null){
                                            strbody += zsleibie.getId().toString()+",";
                                        }
                                    }
                                }
                                if(strbody==null || "".equals(strbody)){
                                    secoundId = "";
                                }else {
                                    secoundId = strbody.substring(0,strbody.length()-1);
                                }

                                //循环添加互斥
                                MutexTestInfo datainfo = new MutexTestInfo();
                                datainfo.setMutexName(huchilist.get(i).getMutexName());
                                datainfo.setTopId(zspingleiId);
                                datainfo.setCategoryId(firstId);
                                datainfo.setCategoryOther(secoundId);
                                datainfo.setMutexReason(huchilist.get(i).getMutexReason());
                                datainfo.setStatus(huchilist.get(i).getStatus());
                                datainfo.setCode(huchilist.get(i).getCode());
                                datainfo.setDingzhi1(dingzhi1);
                                datainfo.setDingzhi2(dingzhi2);
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code4 = parameterService.add_huchi(datainfo);
                            }
                        }
                        if(xuzilist1.size()>0){
                            for (int i=0;i<xuzilist1.size();i++){
                                //循环添加绣字部位
                                CategoryLocationTestInfo datainfo = new CategoryLocationTestInfo();
                                datainfo.setCode(xuzilist1.get(i).getCode());
                                datainfo.setXiuziLocaltion(xuzilist1.get(i).getXiuziLocaltion());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setRemark(xuzilist1.get(i).getRemark());
                                datainfo.setNumbers(xuzilist1.get(i).getNumbers());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setStatus(0);
                                code5 = parameterService.add_xiuzi_location(datainfo);
                            }
                        }
                        if(xuzilist2.size()>0){
                            for (int i=0;i<xuzilist2.size();i++){
                                //循环添加绣字颜色
                                EmbroideredColorTestInfo datainfo = new EmbroideredColorTestInfo();
                                datainfo.setCode(xuzilist2.get(i).getCode());
                                datainfo.setColorName(xuzilist2.get(i).getColorName());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setColorImg(xuzilist2.get(i).getColorImg());
                                datainfo.setNumbers(xuzilist2.get(i).getNumbers());
                                datainfo.setRemark(xuzilist2.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code6 = parameterService.add_xiuzi_color(datainfo);
                            }
                        }
                        if(xuzilist3.size()>0){
                            for (int i=0;i<xuzilist3.size();i++){
                                //循环添加绣字字体
                                EmbroideredFontTestInfo datainfo = new EmbroideredFontTestInfo();
                                datainfo.setCode(xuzilist3.get(i).getCode());
                                datainfo.setEmbroideredName(xuzilist3.get(i).getEmbroideredName());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setEmbroideredImage(xuzilist3.get(i).getEmbroideredImage());
                                datainfo.setNumbers(xuzilist3.get(i).getNumbers());
                                datainfo.setRemark(xuzilist3.get(i).getRemark());
                                datainfo.setIsZitiImg(xuzilist3.get(i).getIsZitiImg());
                                datainfo.setXiuziSize(xuzilist3.get(i).getXiuziSize());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code66 = parameterService.add_xiuzi_fontImg(datainfo);
                            }
                        }
                        if(zhuangselist.size()>0){
                            for (int i=0;i<zhuangselist.size();i++){
                                String dingzhi1="",dingzhi2="";
                                String firstId = "",secoundId="";
                                List<SmalltemplateTestInfo> zsdingzhi_datalist = test_parameterService.query_dingzhiBycategoryId(zspingleiId);
                                SmalltemplateTestInfo ceshidingdatainfo1 = zsparameterService.query_dingzhiBydingzhId(zhuangselist.get(i).getDingzhiId());
                                if(ceshidingdatainfo1!=null){
                                    if(zsdingzhi_datalist.size()>0){
                                        for (int k=0;k<zsdingzhi_datalist.size();k++){
                                            if(ceshidingdatainfo1.getCode().equals(zsdingzhi_datalist.get(k).getCode())){
                                                dingzhi1 = zsdingzhi_datalist.get(k).getId().toString();
                                                break;
                                            }
                                        }
                                    }
                                }
                                //根据类别id查询类别详情
                                MlccCategoryTestInfo leibiedatainfo1 = zsparameterService.select_testcategoryDetail(zhuangselist.get(i).getCategoryId());
                                if(leibiedatainfo1!=null){
                                    MlccCategoryInfo zsleibie = parameterService.select_zscategoryDetailByother(leibiedatainfo1.getCategoryCode(),zspingleiId,dingzhi1);
                                    if(zsleibie!=null){
                                        firstId = zsleibie.getId().toString();
                                    }
                                }
                                //循环添加撞色
                                ContrastcolorTestInfo datainfo = new ContrastcolorTestInfo();
                                datainfo.setTopId(zspingleiId);
                                datainfo.setCode(zhuangselist.get(i).getCode());
                                datainfo.setContrastColorName(zhuangselist.get(i).getContrastColorName());
                                datainfo.setCategoryId(firstId);
                                datainfo.setContrastColorImg(zhuangselist.get(i).getContrastColorImg());
                                datainfo.setSinglePrice2(zhuangselist.get(i).getSinglePrice2());
                                datainfo.setTeamPrice2(zhuangselist.get(i).getTeamPrice2());
                                datainfo.setDingzhiId(dingzhi1);
                                datainfo.setRemark(zhuangselist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                code7 = parameterService.add_zhuangse(datainfo);
                            }
                        }
                        if(bodysizelist1.size()>0){
                            for (int i=0;i<bodysizelist1.size();i++){
                                //循环添加身体尺寸
                                BodySizeTestInfo datainfo = new BodySizeTestInfo();
                                datainfo.setBodySizename(bodysizelist1.get(i).getBodySizename());
                                datainfo.setUnit(bodysizelist1.get(i).getUnit());
                                datainfo.setModuleId(bodysizelist1.get(i).getModuleId());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setNumbers(bodysizelist1.get(i).getNumbers());
                                datainfo.setIsJin(bodysizelist1.get(i).getIsJin());
                                datainfo.setMax(bodysizelist1.get(i).getMax());
                                datainfo.setMin(bodysizelist1.get(i).getMin());
                                datainfo.setIsBitian(bodysizelist1.get(i).getIsBitian());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setCode(bodysizelist1.get(i).getCode());
                                code8 = parameterService.add_testbodySize(datainfo);
                            }
                        }
                        if(fanxiulist.size()>0){
                            for (int i=0;i<fanxiulist.size();i++){
                                //循环添加返修
                                CategoryFanxiuTestInfo datainfo = new CategoryFanxiuTestInfo();
                                datainfo.setBodySizename(fanxiulist.get(i).getBodySizename());
                                datainfo.setUnit(fanxiulist.get(i).getUnit());
                                datainfo.setCategoryId(zspingleiId);
                                datainfo.setNumbers(fanxiulist.get(i).getNumbers());
                                datainfo.setMax(fanxiulist.get(i).getMax());
                                datainfo.setMin(fanxiulist.get(i).getMin());
                                datainfo.setRemark(fanxiulist.get(i).getRemark());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setCode(fanxiulist.get(i).getCode());
                                code9 = parameterService.add_testFanxiuSize(datainfo);
                            }
                        }
                        if(gongyilist.size()>0){
                            for (int i=0;i<gongyilist.size();i++){
                                //循环添加工艺
                                MlccCategoryTestInfo datainfo = new MlccCategoryTestInfo();
                                datainfo.setCategoryCode(gongyilist.get(i).getCategoryCode());
                                datainfo.setCategoryName(gongyilist.get(i).getCategoryName());
                                datainfo.setParentId(gongyilist.get(i).getParentId());
                                datainfo.setImg(gongyilist.get(i).getImg());
                                datainfo.setRemark(gongyilist.get(i).getRemark());
                                datainfo.setTopid(zspingleiId);
                                datainfo.setIsType(4);
                                datainfo.setCategorySex(gongyilist.get(i).getCategorySex());
                                datainfo.setNumbers(gongyilist.get(i).getNumbers());
                                datainfo.setSysOrgCode(sys_org_code);
                                datainfo.setCreateBy(create_by);
                                datainfo.setStatus(0);
                                code10 = parameterService.add_category_plate(datainfo);
                            }
                        }
                    }
                    System.out.println("各个code=="+code2+"="+code3+"="+code4+"="+code5+"="+code6+"="+code66+"="+code7+"="+code8+"="+code9+"="+code10);
                    if(code2>0 || code3>0 || code4>0 || code5>0 || code6>0 || code66>0 || code7>0 || code8>0 || code9>0 || code10>0){
                        return Result.ok("新增成功");
                    }else {
                        return Result.error("新增失败");
                    }
                }else {
                    return Result.error("新增版号失败");
                }
            }
        }catch (Exception e){
            //手动回滚事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("新增版号失败，该编号在该系统已存在，请更换新的编号");
        }
    }


    /**
     * 批量删除--辅料
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_batch_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_batch_material(@RequestBody Map<String,Object> params) {
        List<Integer> ids=(List<Integer>) params.get("ids");
//        System.out.println("===" + ids);
        int code = parameterService.delete_batch_material(ids);
        if(code==1){
            return Result.ok("批量删除成功");
        }else if(code==2){
            return Result.ok("请勾选你要删除的选项");
        }
        else {
            return Result.error("操作失败");
        }
    }

    /**
     * 一键真删除--辅料
     * @param
     * @return boolean
     */
    @PutMapping(value = "/real_delete_material")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> real_delete_material(@RequestBody Map<String,Object> params) {
        String type = params.get("type").toString();
        String category_id = params.get("category_id").toString();
        //获取登录用户信息
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String sys_org_code = sysUser.getOrgCode();
        String create_by = sysUser.getUsername();
//        System.out.println("===" + category_id+"==="+type);
        int code = parameterService.real_delete_material(category_id,type);
        if(code>0){
            //插入日志
            sysBaseAPI.addLog("操作人: " + create_by + "执行了一键清空辅料数据操作", CommonConstant.DEL_FLAG_0,
                    3);
            return Result.ok("一键清空成功");
        }else {
            return Result.error("移除失败");
        }
    }

    /**
     * 批量删除--标准码
     * @param
     * @return boolean
     */
    @PutMapping(value = "/delete_batch_standcode")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Result<?> delete_batch_standcode(@RequestBody Map<String,Object> params) {
        List<String> ids=(List<String>) params.get("ids");
        System.out.println("===" + ids);
        int code = parameterService.delete_batch_standardCode(ids);
        if(code==1){
            return Result.ok("批量删除成功");
        }else if(code==2){
            return Result.ok("请勾选你要删除的选项");
        }
        else {
            return Result.error("操作失败");
        }
    }

}
